From ecfc214399b1788293a9438c89faba4b40bf9d9c Mon Sep 17 00:00:00 2001 From: "iap10@labyrinth.cl.cam.ac.uk" Date: Sun, 30 Nov 2003 23:04:40 +0000 Subject: [PATCH] bitkeeper revision 1.638 (3fca7788evQFw3E81lBB0aqsSAxjwA) Slightly more complicated example script --- .rootkeys | 1 + tools/examples/mynewdom.py | 113 +++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100755 tools/examples/mynewdom.py diff --git a/.rootkeys b/.rootkeys index fe17b6d2ab..f5af9fa921 100644 --- a/.rootkeys +++ b/.rootkeys @@ -42,6 +42,7 @@ 3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py 3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py 3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py +3fca7788tBihusQSq3HJI-YKQTN2iQ tools/examples/mynewdom.py 3fca7700PVj36cZObaFZlQicRiw1pQ tools/examples/pincpu.py 3fbe2f12Bnt8mwmr1ZCP6HWGS6yvYw tools/examples/stopdom.py 3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile diff --git a/tools/examples/mynewdom.py b/tools/examples/mynewdom.py new file mode 100755 index 0000000000..49dba2d339 --- /dev/null +++ b/tools/examples/mynewdom.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +# +# Example script for creating and building a new Linux guest OS for Xen. +# + +import Xc, XenoUtil, sys, os, socket, re + +# Variable declaration. Set these up properly later on, as needed. +nfsserv = nfspath = root_partn = usr_partn = "" +shost = re.search( '([a-zA-Z]+)[-.]', socket.gethostname() ).group(1) + +# STEP 1. Specify kernel image file. +image = "/usr/groups/srgboot/%s/xenolinux.gz" % shost + +# STEP 2. How many megabytes of memory for the new domain? +memory_megabytes = 64 + +# STEP 3. A handy name for your new domain. +domain_name = "My new domain" + +# Allocate new domain +xc = Xc.new() +id = xc.domain_create( mem_kb=memory_megabytes*1024, name=domain_name ) +if id <= 0: + print "Error creating domain" + sys.exit() + +# Set the CPU, or leave to round robin +#xc.domain_pincpu( dom=id, cpu=1 ) + +# STEP 4. Specify IP address, netmask and gateway for the new domain. +ipaddr = XenoUtil.add_to_ip(XenoUtil.addr_of_iface('eth0'),id) +netmask = XenoUtil.get_current_ipmask() +gateway = XenoUtil.get_current_ipgw() + +# STEP 5a. Specify NFS server and path to rootfs (only needed for network boot) +#nfsserv = "ADDRESS" +#nfspath = "FULL_PATH_TO_ROOT_DIR" + +# STEP 5b. Specify root partition on local disc (if not NFS booting) +root_partn = "/dev/sda%d" % (7+id) +# (NB. The following is only needed for a separate shared read-only /usr) +usr_partn = "/dev/sda6" + +# STEP 6. Check that the following cmdline setup is to your taste. +cmdline = "ip="+ipaddr+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off" +if root_partn: + # Boot from local disc. May specify a separate /usr. + cmdline = cmdline + " root="+root_partn+" ro" + if usr_partn: + " usr="+usr_partn +elif nfsserv: + # NFS boot + cmdline = cmdline + " root=/dev/nfs" + cmdline = cmdline + " nfsroot="+nfspath + +if root_partn: + root_info = XenoUtil.lookup_blkdev_partn_info(root_partn) + if not root_info: + print "Could not obtain info on partition '" + root_partn + "'" + sys.exit() + +if usr_partn: + usr_info = XenoUtil.lookup_blkdev_partn_info(usr_partn) + if not usr_info: + print "Could not obtain info on partition '" + usr_partn + "'" + sys.exit() + +if not os.path.isfile( image ): + print "Image file '" + image + "' does not exist" + sys.exit() + + +if xc.linux_build( dom=id, image=image, cmdline=cmdline ): + print "Error building Linux guest OS" + xc.domain_destroy ( dom=id ) + sys.exit() + +if root_partn: + if xc.vbd_create( dom=id, vbd=root_info[0], writeable=1 ): + print "Error creating root VBD" + xc.domain_destroy ( dom=id ) + sys.exit() + if xc.vbd_add_extent( dom=id, + vbd=root_info[0], + device=root_info[1], + start_sector=root_info[2], + nr_sectors=root_info[3] ): + print "Error populating root VBD" + xc.domain_destroy ( dom=id ) + sys.exit() + +if usr_partn: + if xc.vbd_create( dom=id, vbd=usr_info[0], writeable=0 ): + print "Error creating usr VBD" + xc.domain_destroy ( dom=id ) + sys.exit() + if xc.vbd_add_extent( dom=id, + vbd=usr_info[0], + device=usr_info[1], + start_sector=usr_info[2], + nr_sectors=usr_info[3] ): + print "Error populating usr VBD" + xc.domain_destroy ( dom=id ) + sys.exit() + +XenoUtil.setup_vfr_rules_for_vif( id, 0, ipaddr ) + +if xc.domain_start( dom=id ): + print "Error starting domain" + xc.domain_destroy ( dom=id ) + sys.exit() -- 2.30.2